import Vue from "vue";
import VueRouter from "vue-router";
//路由懒加载
let Login = () => import("../views/login"); // 登录组件 ../views/login/index.vue 文件名是index的话可以省略
let Reg = () => import("../views/reg"); //注册组件
let Layout = () => import("../views/layout"); //主界面
let Users = () => import("../components/users"); //用户管理
let Goods = () => import("../components/goods"); //商品管理
let Orders = () => import("../components/orders"); //订单管理
let Comments = () => import("../components/comments"); //评论管理

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    component: Login,
    name: "login",
    meta: {
      //元信息
      ischeck: false, //不需要路由守卫
    },
  },
  {
    path: "/reg",
    component: Reg,
    name: "reg",
    meta: {
      //元信息
      ischeck: false,
    },
  },
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: Layout,
    name: "home",
    redirect: "/home/users",
    children: [
      {
        path: "users",
        component: Users,
      },
      {
        path: "orders",
        component: Orders,
      },
      {
        path: "goods",
        component: Goods,
      },
      {
        path: "comments",
        component: Comments,
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

export default router;
